package com.dhcc.bpm.modules.orga.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.orga.entity.Userhome;
import com.dhcc.bpm.modules.orga.service.IUserhomeService;
import com.dhcc.bpm.modules.orga.vo.UserhomeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;

/**
 * @ClassName UserhomeController
 * @Description 用户门户表 控制器
 * @Author daina
 * @Date 2020/2/24 19:25
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@RestController
@AllArgsConstructor
@RequestMapping("bpm-orga/user")
@Api(value = "用户门户表", tags = "用户门户表接口")
public class UserhomeController extends BladeController {

	private IUserhomeService userService;

	/**
	 * @Description 详情
	 * @Author daina
	 * @Date 10:46 2020/2/25
	 * @param user
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.orga.entity.Userhome>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入user")
	@ApiLog("用户信息 详情")
	@Log(title = "用户信息 详情", businessType = BusinessType.SELECT)
	public R<Userhome> detail(Userhome user) {
		Userhome detail = userService.getOne(Condition.getQueryWrapper(user));
		return R.data(detail);
	}

	/**
	 * @Description 用户门户表
	 * @Author daina
	 * @Date 10:46 2020/2/25
	 * @param user
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.orga.entity.Userhome>>
	 **/
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入user")
	@ApiLog("用户信息列表")
	@Log(title = "用户信息列表", businessType = BusinessType.SELECT)
	public R<IPage<Userhome>> list(@ApiIgnore @RequestParam Map<String, Object> user, Query query) {
		IPage<Userhome> pages = userService.page(Condition.getPage(query), Condition.getQueryWrapper(user,Userhome.class));
		return R.data(pages);
	}

	/**
	 * @Description 分页
	 * @Author daina
	 * @Date 10:46 2020/2/25
	 * @param user
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.orga.vo.UserhomeVO>>
	 **/
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入user")
	@ApiLog("用户信息列表")
	@Log(title = "用户信息列表", businessType = BusinessType.SELECT)
	public R<IPage<UserhomeVO>> page(UserhomeVO user, Query query) {
		IPage<UserhomeVO> pages = userService.selectUserPage(Condition.getPage(query), user);
		return R.data(pages);
	}

	/**
	 * @Description 用户信息列表
	 * @Author daina
	 * @Date 10:46 2020/2/25
	 * @param user
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.orga.vo.UserhomeVO>>
	 **/
	@GetMapping("/listUser")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入user")
	@ApiLog("用户信息列表")
	@Log(title = "用户信息列表", businessType = BusinessType.SELECT)
	public R<IPage<UserhomeVO>> selectUserInfo(UserhomeVO user, Query query) {
		IPage<UserhomeVO> pages = userService.selectUserInfo(Condition.getPage(query), user);
		return R.data(pages);
	}

	/**
	 * @Description 新增 用户门户表
	 * @Author daina
	 * @Date 10:46 2020/2/25
	 * @param user
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入user")
	@ApiLog("新增 用户门户表")
	@Log(title = "新增 用户门户表", businessType = BusinessType.INSERT)
	public R save(@Valid @RequestBody Userhome user) {
		return R.status(userService.save(user));
	}

	/**
	 * @Description 用户门户表
	 * @Author daina
	 * @Date 10:46 2020/2/25
	 * @param user
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入user")
	@ApiLog("修改 用户门户表")
	@Log(title = "修改 用户门户表", businessType = BusinessType.UPDATE)
	public R update(@Valid @RequestBody Userhome user) {
		return R.status(userService.updateById(user));
	}

	/**
	 * @Description 新增或修改 用户门户表
	 * @Author daina
	 * @Date 10:46 2020/2/25
	 * @param user
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入user")
	@ApiLog("新增或修改 用户门户表")
	@Log(title = "新增或修改 用户门户表", businessType = BusinessType.INSERT)
	public R submit(@Valid @RequestBody Userhome user) {
		return R.status(userService.saveOrUpdate(user));
	}


	/**
	 * @Description 删除 用户门户表
	 * @Author daina
	 * @Date 10:47 2020/2/25
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "删除 用户门户表", notes = "传入ids")
	@ApiLog("删除 用户门户表")
	@Log(title = "删除 用户门户表", businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(userService.deleteLogic(Func.toLongList(ids)));
	}

	
}
